import * as THREE from "three"
import CommandBinder from "../CommandBinder"
import SettingsData from "../data/SettingsData"
import EngineContext from "../EngineContext"
import InputIniModule from "../module/InputIniModule"
import RaycasterModule from "../module/RaycasterModule"
import WebGLScene from "../three/WebGLScene"
import RenderLayers, { RenderLayer } from "../utils/RenderLayers"
import { Subscription } from "../utils/Subscription"
import ExtBase from "./content/ext.base"
import ExtBtpic from "./content/ext.btpic"
import ExtCloud from "./content/ext.cloud"
import ExtFbx from "./content/ext.fbx"
import ExtGltf from "./content/ext.gltf"
import ExtJm3 from "./content/ext.jm3"
import ExtMp4 from "./content/ext.mp4"
import ExtMp5 from "./content/ext.mp5"
import ExtMp6 from "./content/ext.mp6"
import ExtOBJ from "./content/ext.obj"
import ExtPic from "./content/ext.pic"
import ExtRobot from "./content/ext.robot"
import ExtSnow from "./content/ext.snow"
import ExtSprite from "./content/ext.sprite"
import ExtText from "./content/ext.text"
import ExtTmt from "./content/ext.tmt"
import ExtV3d from "./content/ext.v3d"
import ExtVideo360 from "./content/ext.video360"
import ExtWater from "./content/ext.water"
import ExtObj from "./ExtObj"
import { ExtObjType } from "./ExtObj.enum"
import ExtObjViewData from "./ExtObjViewData"
export default class ExtObjRender {
  input: InputIniModule
  layer: RenderLayer
  commandBinder: CommandBinder
  raycaster: RaycasterModule
  container: THREE.Object3D
  bindings: Partial<Subscription>[]
  extObjViewData: ExtObjViewData
  settingsData: SettingsData
  scene: WebGLScene
  sweepToMesh: Record<string, THREE.Mesh>
  hasRender: boolean
  readonly: boolean
  extToClass: Record<string, ExtBase>
  constructor(scene, input, settings, extObjViewData, layer = RenderLayers.ALL, readonly: boolean = false) {
    this.scene = scene
    this.input = input
    this.settingsData = settings
    this.extObjViewData = extObjViewData
    this.container = new THREE.Object3D()
    this.layer = layer
    this.bindings = []
    this.hasRender = !1
    this.readonly = readonly
    this.extToClass = {}
  }
  init() {
    this.extObjViewData.iterate(this.createExt.bind(this))
  }
  render() {
    const isOpen = this.settingsData.tryGetProperty("extobj", !0)
  }
  createExt(ext: ExtObj) {
    let extClass: ExtBase
    switch (ext.type) {
      case ExtObjType.CLOUD:
        extClass = new ExtCloud(ext)
        break
      case ExtObjType.FBX:
        extClass = new ExtFbx(ext)
        break
      case ExtObjType.GLTF:
        extClass = new ExtGltf(ext)
        break
      case ExtObjType.Jm3:
        extClass = new ExtJm3(ext)
        break
      case ExtObjType.MP5:
        extClass = new ExtMp5(ext)
        break
      case ExtObjType.MP6:
        extClass = new ExtMp6(ext)
        break
      case ExtObjType.NEWMP4:
        extClass = new ExtMp4(ext)
        break
      case ExtObjType.OBJ:
        extClass = new ExtOBJ(ext)
        break
      case ExtObjType.PIC:
        extClass = new ExtPic(ext)
        break
      case ExtObjType.Robot:
        extClass = new ExtRobot(ext)
        break
      case ExtObjType.SNOW:
        extClass = new ExtSnow(ext)
        break
      case ExtObjType.SPRITE:
        extClass = new ExtSprite(ext)
        break
      case ExtObjType.TEXT:
        extClass = new ExtText(ext)
        break
      case ExtObjType.V3D:
        extClass = new ExtV3d(ext)
        break
      case ExtObjType.VIDEO360:
        extClass = new ExtVideo360(ext)
        break
      case ExtObjType.WATER:
        extClass = new ExtWater(ext)
        break
      case ExtObjType.btPic:
        extClass = new ExtBtpic(ext)
        break
      case ExtObjType.tmt:
        extClass = new ExtTmt(ext)
        break
    }
    this.extToClass[ext.id] = extClass
  }
  async activate(engine: EngineContext) {}
  deactivate(engine: EngineContext) {
    for (const e of this.bindings) e.cancel()
    this.bindings.length = 0
  }
}
